package com.shopReduce.service.impl;


import java.util.List;

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.shopReduce.bean.ReduceProgramme;
import com.shopReduce.dao.ReduceProgrammeMapper;
import com.shopReduce.service.IReduceProgrammeService;

import shopBean.common.Enum.StatusAll;
import shopBean.common.Exception.MyException;
import shopBean.common.bean.RestResult;
import shopBean.common.responseCode.Status;
import shopBean.common.utils.DateCommonUtils;
import shopBean.common.utils.RestResultGenerator;
import shopBean.common.utils.UUIDGenerator;
@Service("reduceProgrammeService")
public class ReduceProgrammeServiceImpl implements IReduceProgrammeService{
	@Autowired
	ReduceProgrammeMapper reduceProgrammeMapper;
	public List<ReduceProgramme> list(ReduceProgramme search) {
		// TODO Auto-generated method stub
		return reduceProgrammeMapper.list(search);
	}
	@Transactional
	public RestResult insert(ReduceProgramme reduceProgramme) {
		// TODO Auto-generated method stub
		
		if(this.getByName(reduceProgramme.getName()) != null) {
			return RestResultGenerator.genErrorResult("添加失败，名称已存在", null, Status.sys_name_is_exits);
		}
		reduceProgramme.setId(UUIDGenerator.generate38());
		reduceProgramme.setCreateDate(DateCommonUtils.getCurrent());
		reduceProgramme.setStatus(StatusAll.normal);
		return RestResultGenerator.genSuccessResult(reduceProgrammeMapper.insert(reduceProgramme));
	}

	public RestResult<ReduceProgramme> getByName(String name) {
		// TODO Auto-generated method stub
		return RestResultGenerator.genSuccessResult(reduceProgrammeMapper.getByName(name));
	}

	public long listCount(ReduceProgramme search) {
		// TODO Auto-generated method stub
		return reduceProgrammeMapper.listCount(search);
	}
	@Transactional
	public RestResult updateStatus(String id,StatusAll status) {
		// TODO Auto-generated method stub
		return RestResultGenerator.genSuccessResult(reduceProgrammeMapper.updateStatus(id,status));
	}

	@Override
	public ReduceProgramme get(String id) {
		// TODO Auto-generated method stub
		return this.reduceProgrammeMapper.get(id);
	}

	@Override
	public RestResult<List<ReduceProgramme>> getByShopIdAndStatus(String shopId, StatusAll status) {
		// TODO Auto-generated method stub
		return RestResultGenerator.genSuccessResult(reduceProgrammeMapper.getByShopIdAndStatus(shopId, status));
	}

	@Override
	public RestResult<ReduceProgramme> getFirstByShopIdAndStatus(String shopId, StatusAll status) {
		// TODO Auto-generated method stub
		return RestResultGenerator.genSuccessResult(reduceProgrammeMapper.getFirstByShopIdAndStatus(shopId, status));
	}
	
}
